package com.chat.xx.utiles;

import com.chat.xx.config.webSocket.NettyServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executor;

@Slf4j
@Component
public class Run implements ApplicationRunner {
    @Autowired
    private NettyServer nettyServer;
    @Qualifier("applicationTaskExecutor")
    @Autowired
    private Executor executor;
    @Override
    public void run(ApplicationArguments args){
        log.info("---------------------系统初始化---------------------");
        log.info("---------------------启动websocket服务器---------------------");
        executor.execute(() -> {
            try {
                log.info("---------------------websocket服务器启动成功---------------------");
                nettyServer.start();
            } catch (Exception e) {
                e.printStackTrace();
                log.info("---------------------websocket服务器启动失败---------------------");
            }
        });
    }
}
